package com.fxw.hodgepodge.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.fxw.mylibrary.BaseAppContext;

import butterknife.ButterKnife;
import butterknife.Unbinder;


/**
 * @author xianwen.fu
 * @version v1.0
 * @Title 父类fragment，所有fragment继承该类
 * @Description:
 * @date 2016/10/15 13:47
 */
public abstract class BaseFragment extends Fragment {
    protected Context mContext;
    protected BaseAppContext mApplication;
    protected Unbinder mUnBinder;
    protected View rootView;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        mContext = context;
        mApplication = (BaseAppContext) getActivity().getApplication();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (rootView == null)
            rootView = inflater.inflate(getLayoutResId(), container, false);
        return rootView;

    }

    @LayoutRes
    protected abstract int getLayoutResId();

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mUnBinder = ButterKnife.bind(this, view);
        initData();
        initListeners();
    }

    protected abstract void initListeners();

    protected abstract void initData();

    @Override
    public void onStart() {
        super.onStart();

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        mUnBinder.unbind();
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mContext = null;
    }
}
